package com.androidvizlab.bachelor;

import java.util.Locale;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * Starts an Activity that show info about the about.
 * The activity is shown as a dialog.
 * @author TheHive
 */
public class About extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.about);
		
		setPreferredLanguage();
		
		Button close = (Button) this.findViewById(R.id.bAbout);
		close.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				finish();
			}
			
		});
	}
	
	@Override
	public void finish()
	{
		super.finish();
	}
	
	/**
	 * Set language selected in the preference
	 * language option settings. 
	 */
	public void setPreferredLanguage()
	{
		Locale locale = null;
		Configuration config = null;
		
		SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
		StringBuilder builder = new StringBuilder();
		  
		builder.append(sharedPrefs.getString("supported_language", "ENGLISH"));
		  
		  if(builder.toString().equals("English"))
		  {
			  locale = new Locale("en");
              Locale.setDefault(locale);
              config = new Configuration();
              config.locale = locale;
              getBaseContext().getResources()
                      .updateConfiguration(
                              config,
                              getBaseContext().getResources()
                                      .getDisplayMetrics());
		  }
		  else if(builder.toString().equals("Norwegian"))
		  {
			  locale = new Locale("no");
              Locale.setDefault(locale);
              config = new Configuration();
              config.locale = locale;
              getBaseContext().getResources()
                      .updateConfiguration(
                              config,
                              getBaseContext().getResources()
                                      .getDisplayMetrics());
		  }
		  else
		  {
			  //TODO
		  }

	}

}
